package com.account.boot.commons.result;

/**
 * API层数据返回DO
 * 
 * @author RoZz
 *
 */
public class APIResultDO {
	
	/**
	 * 公用线程池
	 */
	final static public int CODE_SUCCESS = 0;

	final static public String MSG_SUCCESS = "success";

	final static public int CODE_ERROR_EXCEPTION = -99;

	final static public String MSG_ERROR_EXCEPTION = "系统未知异常";
	
	private int code;
	private String msg;
	private Object data;

	public APIResultDO(int code, String msg) {
		super();
		this.code = code;
		this.msg = msg;
	}

	/**
	 * 组装成功返回结果
	 * 
	 * @return
	 */
	public static APIResultDO buildSuccessResult() {
		return new APIResultDO(CODE_SUCCESS, MSG_SUCCESS);
	}

	/**
	 * 组装失败返回结果
	 * 
	 * @return
	 */
	public static APIResultDO buildDefaultFailureResult() {
		return new APIResultDO(CODE_ERROR_EXCEPTION, MSG_ERROR_EXCEPTION);
	}
	
	/**
	 * 组装指定错误信息枚举返回结果
	 * @param apiResultDO
	 * @param resultCodeInterface
	 * @return
	 */
	public static APIResultDO buildFailureResult(APIResultDO apiResultDO,ResultCodeInterface resultCodeInterface){
		apiResultDO.setCode(resultCodeInterface.getResultCode());
		apiResultDO.setMsg(resultCodeInterface.getMessage());
		return apiResultDO;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}
	
}
